home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / vpwnd.cpp1 < prev    next >
Encoding:
Text File  |  2001-10-16  |  3.2 KB  |  142 lines

  1. /******************************************************************/
  2. /*                                                                */
  3. /*                      TurboCAD for Windows                      */
  4. /*                   Copyright (c) 1993 - 2001                    */
  5. /*             International Microcomputer Software, Inc.         */
  6. /*                            (IMSI)                              */
  7. /*                      All rights reserved.                      */
  8. /*                                                                */
  9. /******************************************************************/
  10.  
  11. // VPWnd.cpp : implementation file
  12. // TurboCAD SDK: new class implementation
  13.  
  14. #include "stdafx.h"
  15. #include "MakeDwg.h"
  16. #include "VPWnd.h"
  17.  
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CViewWnd
  26. // TurboCAD SDK: class created to manage view on dialog box
  27.  
  28. CViewWnd::CViewWnd() :
  29.     m_pView(NULL),
  30.     m_pIDrawing(NULL)
  31. {
  32. }
  33.  
  34. CViewWnd::~CViewWnd()
  35. {
  36.     SetView(NULL);
  37. }
  38.  
  39.  
  40. BEGIN_MESSAGE_MAP(CViewWnd, CWnd)
  41.     //{{AFX_MSG_MAP(CViewWnd)
  42.     ON_WM_PAINT()
  43.     ON_WM_ERASEBKGND()
  44.     //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46.  
  47. // TurboCAD SDK: set the view, if one already exists, delete and release it
  48. //               before assigning the new one.
  49. void CViewWnd::SetView(View* pView)
  50. {
  51.     if (m_pView != NULL)
  52.     {
  53.         // Delete view object
  54.         m_pView->Delete();
  55.  
  56.         // Decrement reference count
  57.         m_pView->Release();
  58.         m_pView = NULL;
  59.         if (m_pIDrawing != NULL)
  60.         {
  61.             m_pIDrawing->Release();
  62.             m_pIDrawing = NULL;
  63.         }
  64.     }
  65.  
  66.     if (pView == NULL)
  67.         return;
  68.  
  69.     m_pView = pView;
  70.  
  71.     // Increment reference count
  72.     m_pView->AddRef();
  73.  
  74.     // Map window to view
  75.     m_pView->put_HWND((long)m_hWnd);
  76.  
  77.     // Keep a reference to the drawing
  78.     m_pView->get_Drawing(&m_pIDrawing);
  79.  
  80.     // zoom to drawing extents and invalidate the window
  81.     ZoomAndInvalidate();
  82. }
  83.  
  84. IDrawing* CViewWnd::GetDrawing()
  85. {
  86.     if (m_pIDrawing != NULL)
  87.         m_pIDrawing->AddRef();
  88.     return m_pIDrawing;
  89. }
  90.  
  91. Graphics* CViewWnd::GetGraphics()
  92. {
  93.     Graphics* pGraphics = NULL;
  94.     if (m_pIDrawing != NULL)
  95.         m_pIDrawing->get_Graphics(&pGraphics);
  96.     return pGraphics;
  97. }
  98.  
  99. // TurboCAD SDK: zoom to drawing extents and invalidate the window
  100. void CViewWnd::ZoomAndInvalidate()
  101. {
  102.     // No view, exit
  103.     if (m_pView == NULL)
  104.         return;
  105.  
  106.     // Zoom to extents
  107.     HRESULT hRes = m_pView->ZoomToExtents();
  108.     if (FAILED(hRes))
  109.     {
  110.     }
  111.  
  112.     // Invalidate window to force redraw
  113.     Invalidate();
  114. }
  115.  
  116. /////////////////////////////////////////////////////////////////////////////
  117. // CViewWnd message handlers
  118.  
  119. // TurboCAD SDK: override OnPaint to refresh the view
  120. void CViewWnd::OnPaint() 
  121. {
  122.     CPaintDC dc(this); // device context for painting
  123.     
  124.     if (m_pView == NULL)
  125.         return;
  126.  
  127.     // Force redraw of view window
  128.     HRESULT hRes = m_pView->Refresh();
  129.     if (FAILED(hRes))
  130.     {
  131.     }
  132. }
  133.  
  134. // TurboCAD SDK: override OnEraseBkgnd to reset the drawing area
  135. BOOL CViewWnd::OnEraseBkgnd(CDC* pDC) 
  136. {
  137.     CRect rect;
  138.     GetClientRect(rect);
  139.     pDC->FillSolidRect(rect, ::GetSysColor(COLOR_WINDOW));
  140.     return TRUE;
  141. }
  142.